var searchName = null;
var companyId = null;
$(function () {

	$("#searchButton").click(function () {
		searchName = $("#searchName").val().trim();
		companyId = $("#companyId").val();
		if("" == companyId || undefined == companyId)
			companyId = null;
		console.log(companyId);
		initdata();
	});

//	initdata();
	function initdata() {
		$.ajax({
			url : ctx+"/area/listData",
			type:'GET',
			async:false,
			dataType : 'json',
			data : {
				"name":searchName,
				"name":searchName,
				"companyId": companyId
			},
			success : function(result){
				$(".area_container").html("");
				var content="";
				$("#NoData").text("");
				if (result.length!=0) {
					$(result).each(function(index,area){
						content+="<form action='"+ctx+"/area/save' class='form-horizontal' method='post'>"+
							"<input type='hidden' name='id' value='"+area.id+"'>"+
							"<div class='col-md-12'>"+
							"<div class='panel panel-default'>"+
							"<div class='panel-heading'>"+
							"<span class='name_span'>"+area.name+"</span>"+
							"<input type='text' value='"+area.name+"' name='name' class='name_input' style='width:150px;display:none;' required/>"+
							"<button type='button' data='"+area.id+"' class='deleteArea pull-right button button-pill button-flat-caution button-tiny'><span class='glyphicon glyphicon-remove'></span>&nbsp;删除</button>"+
							"<button type='button' class='area-add pull-right button button-pill button-flat-action button-tiny'><span class='glyphicon glyphicon-plus'></span>&nbsp;新增时间段</button>"+
							"<button type='button' class='area-edit pull-right button button-pill button-flat-primary button-tiny'><span class='glyphicon glyphicon-edit'></span>&nbsp;修改</button>"+
							"<button type='button' class='area-save pull-right button button-pill button-flat button-tiny'><span class='glyphicon glyphicon-floppy-disk'></span>&nbsp;保存</button>"+
							"</div>"+
							"<div class='panel-body  time_panel_body'>";
						if (area.chargeStartTimes != null && area.chargeStartTimes.length !=0) {
							var chargeStartTimes = area.chargeStartTimes;
							$(area.chargeStartTimes).each(function(time_index,time){
								content+=
									"<div class='item-length'>"+
									"<div class='panel-group'>"+
									"<div class='panel panel-default'>"+
									"<div class='panel-heading'>"+
									"<h4 class='panel-title'>"+
									"<a data-toggle='collapse' href='#collapseOne_"+time.id+"'>"+
									"展开  "+
									"</a>"+
									"<span class='time_content'>"+
									"开始服务时间（"+
									"<span class='this_startHour'>"+addZero(time.startHour) +"</span>"+

									"<select name='chargeStartTimes["+time_index+"].startHour' class='startHour_select bottom_border' style='display:none;'>";
								for (var t = 0; t < 24; t++) {
									var selected="";
									if (time.startHour == t) {
										selected="selected";
									}
									if (t==10) {
										content+="<option value='"+t+"' "+selected+">"+t+"</option>";
									} else {
										content+="<option value='"+t+"' "+selected+" >"+addZero(t)+"</option>";
									}
								}
								content+="</select>"+
									"："+
									"<span class='this_startMinute'>"+ addZero(time.startMinute) +"</span>"+
									"<select name='chargeStartTimes["+time_index+"].startMinute' class='startMinute_select bottom_border' style='display:none;'>";
								for (var t = 0; t < 24; t++) {
									var selected="";
									if (time.startMinute == t) {
										selected="selected";
									}
									if (t==10) {
										content+="<option value='"+t+"' "+selected+">"+t+"</option>";
									} else {
										content+="<option value='"+t+"' "+selected+" >"+addZero(t)+"</option>";
									}
								}
								content+="</select>"+
									"-"+
									"<span class='this_endHour'>"+ addZero(time.endHour) +"</span>"+
									"<select name='chargeStartTimes["+time_index+"].endHour' class='endHour_select bottom_border' style='display:none;'>";
								for (var t = 0; t < 60; t++) {
									var selected="";
									if (time.endHour == t) {
										selected="selected";
									}
									if (t==10) {
										content+="<option value='"+t+"' "+selected+">"+t+"</option>";
									} else {
										content+="<option value='"+t+"' "+selected+" >"+addZero(t)+"</option>";
									}
								}
								content+="</select>"+
									"："+
									"<span class='this_endMinute'>"+ addZero(time.endMinute) +"</span>"+
									"<select name='chargeStartTimes["+time_index+"].endMinute' class='endMinute_select bottom_border' style='display:none;'>";
								for (var t = 0; t < 60; t++) {
									var selected="";
									if (time.endMinute == t) {
										selected="selected";
									}
									if (t==10) {
										content+="<option value='"+t+"' "+selected+">"+t+"</option>";
									} else {
										content+="<option value='"+t+"' "+selected+" >"+addZero(t)+"</option>";
									}
								}
								content+="</select>"+
									"）"+
									"起步价<span class='this_cost'>"+time.cost+"</span><input type='number' value='"+time.cost+"' name='chargeStartTimes["+time_index+"].cost' data-name='chargeStartTimes["+time_index+"]' class='cost_input bottom_border' style='width:60px;display:none;' required min='0' />元"+
									"</span>"+
									"<span class='time_button pull-right'>"+
									"<button type='button' class='pull-right btn btn-default btn-xs time_button_delete'>删除</button>"+
									"<button type='button' class='pull-right btn btn-default btn-xs time_button_edit'>修改</button>"+
									"<button type='button' class='pull-right btn btn-default btn-xs time_button_add'>添加里程价格</button>"+
									"<button type='button' class='pull-right btn btn-default btn-xs weight_button_add'>添加重量价格</button>"+
									"</span>"+
									"</h4>"+
									"</div>"+

									"<div id='collapseOne_"+time.id+"' class='panel-collapse collapse in'>"+
									"<div class='panel-body'>"+
									"<table class='table table-condensed table-bordered distance-table'>"+
									"<tr style='font-size:14px;'>"+
									"<th>开始里程(公里)</th>"+
									"<th>结束里程(公里)</th>"+
									"<th>增长价(元)</th>"+
									"<th>操作</th>"+
									"</tr>";
								if (time.chargeStartDistances != null && time.chargeStartDistances.size !=0) {
									var distancelist=time.chargeStartDistances;
									$(distancelist).each(function(distance_index,distance){
										content+="<tr class='distance_tr'>";
										if (distance_index==0) {
											content+="<td>" + distancelist[distance_index].startdistance + "</td>";
										}else {
											content+="<td><span>"+distancelist[distance_index-1].distance+"</span><input class='distance_td_distance_start' type='number' required  value='"+distancelist[distance_index-1].distance+"' style='display:none;' /></td>";
										}
										content+="<td><span>"+distance.distance+"</span><input class='distance_td_distance' type='number' required value='"+distance.distance+"' style='display:none;' /></td>"+
											"<td><span>"+distance.money+"</span><input class='distance_td_money' type='number' required value='"+distance.money+"' style='display:none;' /></td>"+
											"<td>"+
											"<a href='javascript:;' class='distance_td_edit'>修改</a>"+
											"<a href='javascript:;' class='distance_td_delete'>删除</a>"+
											"</td>"+
											"</tr>";
									});
								}
								content+="</table>"+
									"<hr/>"+
									"<table class='table table-condensed table-bordered weight-table'>"+
									"<tr style='font-size:14px;'>"+
									"<th>开始重量(公斤)</th>"+
									"<th>结束重量(公斤)</th>"+
									"<th>增长价(元)</th>"+
									"<th>操作</th>"+
									"</tr>";
								if (time.chargeStartNewWeights != null && time.chargeStartNewWeights.size !=0) {
									var weightlist=time.chargeStartNewWeights;
									$(weightlist).each(function(weight_index,weight){
										content+="<tr class='weight_tr'>";
										if (weight_index==0) {
											content+="<td>0</td>";
										}else {
											content+="<td><span>"+weightlist[weight_index-1].weight+"</span><input class='weight_td_weight_start' type='number' required  value='"+weightlist[weight_index-1].weight+"' style='display:none;' /></td>";
										}
										content+="<td><span>"+weight.weight+"</span><input class='weight_td_weight' type='number' required value='"+weight.weight+"' style='display:none;' /></td>"+
											"<td><span>"+weight.money+"</span><input class='weight_td_money' type='number' required value='"+weight.money+"' style='display:none;' /></td>"+
											"<td>"+
											"<a href='javascript:;' class='weight_td_edit'>修改</a>"+
											"<a href='javascript:;' class='weight_td_delete'>删除</a>"+
											"</td>"+
											"</tr>";
									});
								}
								content+="</table>"+
									"<hr/>"+
									"<span class='time_content2'>"+
									"超过（<span class='this_qblc'>"+time.qblc+"</span><input type='number' value='"+time.qblc+"' name='chargeStartTimes["+time_index+"].qblc' class='qblc_input bottom_border' style='width:60px;display:none;' required min='0'/>公里）"+
									"以后每<span class='this_djglUnit'>"+time.djglUnit+"</span><input type='number' value='"+time.djglUnit+"' name='chargeStartTimes["+time_index+"].djglUnit' class='djglUnit_input bottom_border' style='width:60px;display:none;' required min='0'/>公里"+
									// "（不足<span class='this_djglThresholdt'>"+time.djglThresholdt+"</span><input type='number' value='"+time.djglThresholdt+"' name='chargeStartTimes["+time_index+"].djglThresholdt' class='djglThresholdt_input bottom_border' style='width:60px;display:none;' required min='0'/>公里不计费）"+
									"加收<span class='this_djglCost'>"+time.djglCost+"</span><input type='number' value='"+time.djglCost+"' name='chargeStartTimes["+time_index+"].djglCost' class='djglCost_input bottom_border' style='width:60px;display:none;' required min='0'/>元 ；"+
									"<p></p>"+
									"起步后<span class='this_qbsj'>"+time.qbsj+"</span><input type='number' value='"+time.qbsj+"' name='chargeStartTimes["+time_index+"].qbsj' class='qbsj_input bottom_border' style='width:60px;display:none;' required min='0'/>分钟内不收费， "+
									"以后每<span class='this_djsjUnit'>"+time.djsjUnit+"</span><input type='number' value='"+time.djsjUnit+"' name='chargeStartTimes["+time_index+"].djsjUnit' class='djsjUnit_input bottom_border' style='width:60px;display:none;' required min='0'/>分钟"+
									// "（不足<span class='this_djsjThresholdt'>"+time.djsjThresholdt+"</span><input type='number' value='"+time.djsjThresholdt+"' name='chargeStartTimes["+time_index+"].djsjThresholdt' class='djsjThresholdt_input bottom_border' style='width:60px;display:none;' required min='0'/>分钟不收费）"+
									"加收<span class='this_djsjCost'>"+time.djsjCost+"</span><input type='number' value='"+time.djsjCost+"' name='chargeStartTimes["+time_index+"].djsjCost' class='djsjCost_input bottom_border' style='width:60px;display:none;' required min='0'/>元 ；"+
									"<p></p>"+
									"免费等候<span class='this_mfdhsj'>"+time.mfdhsj+"</span><input type='number' value='"+time.mfdhsj+"' name='chargeStartTimes["+time_index+"].mfdhsj' class='mfdhsj_input bottom_border' style='width:60px;display:none;' required min='1'/>分钟， "+
									"到达则立即加收<span class='this_dhsjAtonceCost'>"+time.dhsjAtonceCost+"</span><input type='number' value='"+time.dhsjAtonceCost+"' name='chargeStartTimes["+time_index+"].dhsjAtonceCost' class='dhsjAtonceCost_input bottom_border' style='width:60px;display:none;' required min='0'/>元 ，"+
									"后每<span class='this_dhsjUnit'>"+time.dhsjUnit+"</span><input type='number' value='"+time.dhsjUnit+"' name='chargeStartTimes["+time_index+"].dhsjUnit' class='dhsjUnit_input bottom_border' style='width:60px;display:none;' required min='0'/>分钟"+
									// "（ 低于<span class='this_dhsjThresholdt'>"+time.dhsjThresholdt+"</span><input type='number' value='"+time.dhsjThresholdt+"' name='chargeStartTimes["+time_index+"].dhsjThresholdt' class='dhsjThresholdt_input bottom_border' style='width:60px;display:none;' required min='0'/>分钟不计费）"+
									"加收<span class='this_dhsjCost'>"+time.dhsjCost+"</span><input type='number' value='"+time.dhsjCost+"' name='chargeStartTimes["+time_index+"].dhsjCost' class='dhsjCost_input bottom_border' style='width:60px;display:none;' required min='0'/>元。"+
									"<p></p>"+
									"超过（<span class='this_cgzl'>"+time.cgzl+"</span><input type='number' value='"+time.cgzl+"' name='chargeStartTimes["+time_index+"].cgzl' class='cgzl_input bottom_border' style='width:60px;display:none;' required min='0'/>公斤）"+
									"以后每<span class='this_zlUnit'>"+time.zlUnit+"</span><input type='number' value='"+time.zlUnit+"' name='chargeStartTimes["+time_index+"].zlUnit' class='zlUnit_input bottom_border' style='width:60px;display:none;' required min='0'/>公斤"+
									// "（不足<span class='this_zlThresholdt'>"+time.zlThresholdt+"</span><input type='number' value='"+time.zlThresholdt+"' name='chargeStartTimes["+time_index+"].zlThresholdt' class='zlThresholdt_input bottom_border' style='width:60px;display:none;' required min='0'/>公斤不计费）"+
									"加收<span class='this_zlCost'>"+time.zlCost+"</span><input type='number' value='"+time.zlCost+"' name='chargeStartTimes["+time_index+"].zlCost' class='zlCost_input bottom_border' style='width:60px;display:none;' required min='0'/>元 ；"+
									"</span>"+
									"</div>"+
									"</div>"+
									"</div>"+
									"</div>"+
									"</div>";
							});
						}


						content+="<h4 class='text-primary'>收费说明：</h4>"+
							"<p class='text-muted'>"+
							"<span class='memo_span'>"+area.memo+"</span>"+
							"<textarea class='memo_textarea' cols='100' rows='5' style='display:none;' name='memo'>"+area.memo+"</textarea>"+
							"</p>"+
							"</div>"+
							"</div>"+
							"</div>"+
							"</form>";
					});
					$(".area_container").append(content);
				} else {
					$("#NoData").text("当前页面暂无记录 ");
				}

			}

		});
	}
	$(document).on("click",".area-save",function (){
		var thisform=$(this).parent().parent().parent().parent();


		if($.trim(thisform.find(".name_input").val())==""){
			alert("请填写收费标准名称");
			thisform.find(".name_input").focus();
			return false;
		}

		if (thisform.find(".item-length").length == 0) {
			alert("至少添加一条时间段");
			return false;
		}

		var formable = true;

		var numPoint = /^(\d+)(.[0-9]{0,2})?$/;
		var numPointweight = /^(\d+)(.[0-9]{0,1})?$/;
		var numPoint2 = /^(\d+)$/;
		$(thisform).find(".item-length").each(function (index, element) {

			if($(element).find(".cost_input").val()!="" && !numPoint.test($(element).find(".cost_input").val())){
				alert("起步价格式不正确。");
				$(element).find(".time_button_edit").click();
				$(element).find(".cost_input").focus();
				formable=false;
				return false;
			}else if($(element).find(".qblc_input").val()!="" && !numPoint.test($(element).find(".qblc_input").val())){
				alert("公里数格式不正确。");
				$(element).find(".time_button_edit").click();
				$(element).find(".qblc_input").focus();
				formable=false;
				return false;
			}else if($(element).find(".djglUnit_input").val()!="" && !numPoint.test($(element).find(".djglUnit_input").val())){
				alert("公里数格式不正确。");
				$(element).find(".time_button_edit").click();
				$(element).find(".djglUnit_input").focus();
				formable=false;
				return false;
				// }else if($(element).find(".djglThresholdt_input").val()!="" && !numPoint.test($(element).find(".djglThresholdt_input").val())){
				// 	alert("公里数格式不正确。");
				// 	$(element).find(".time_button_edit").click();
				// 	$(element).find(".djglThresholdt_input").focus();
				// 	formable=false;
				// 	return false;
			}else if($(element).find(".djglCost_input").val()!="" && !numPoint.test($(element).find(".djglCost_input").val())){
				alert("金额格式不正确。");
				$(element).find(".time_button_edit").click();
				$(element).find(".djglCost_input").focus();
				formable=false;
				return false;
			}else if($(element).find(".qbsj_input").val()!="" && !numPoint2.test($(element).find(".qbsj_input").val())){
				alert("分钟格式不正确。");
				$(element).find(".time_button_edit").click();
				$(element).find(".qbsj_input").focus();
				formable=false;
				return false;
			}else if($(element).find(".djsjUnit_input").val()!="" && !numPoint2.test($(element).find(".djsjUnit_input").val())){
				alert("分钟格式不正确。");
				$(element).find(".time_button_edit").click();
				$(element).find(".djsjUnit_input").focus();
				formable=false;
				return false;
				// }else if($(element).find(".djsjThresholdt_input").val()!="" && !numPoint2.test($(element).find(".djsjThresholdt_input").val())){
				// 	alert("分钟格式不正确。");
				// 	$(element).find(".time_button_edit").click();
				// 	$(element).find(".djsjThresholdt_input").focus();
				// 	formable=false;
				// 	return false;
			}else if($(element).find(".djsjCost_input").val()!="" && !numPoint.test($(element).find(".djsjCost_input").val())){
				alert("金额格式不正确。");
				$(element).find(".time_button_edit").click();
				$(element).find(".djsjCost_input").focus();
				formable=false;
				return false;
			}/*else if($(element).find(".distance_td_money").val()!="" && !numPoint.test($(element).find(".distance_td_money").val())){
    			alert("增长价格式不正确。");
    			console.log($(element).find(".distance_td_money").val());
    			$(element).find(".time_button_edit").click();
    			$(element).find(".djsjCost_input").focus();
    			formable=false;
    			return false;
    		}*/else if($(element).find(".mfdhsj_input").val()!="" && !numPoint2.test($(element).find(".mfdhsj_input").val())){
				alert("分钟格式不正确。");
				$(element).find(".time_button_edit").click();
				$(element).find(".mfdhsj_input").focus();
				formable=false;
				return false;
			}else if($(element).find(".dhsjAtonceCost_input").val()!="" && !numPoint.test($(element).find(".dhsjAtonceCost_input").val())){
				alert("金额格式不正确。");
				$(element).find(".time_button_edit").click();
				$(element).find(".dhsjAtonceCost_input").focus();
				formable=false;
				return false;
			}else if($(element).find(".dhsjUnit_input").val()!="" && !numPoint2.test($(element).find(".dhsjUnit_input").val())){
				alert("分钟格式不正确。");
				$(element).find(".time_button_edit").click();
				$(element).find(".dhsjUnit_input").focus();
				formable=false;
				return false;
				// }else if($(element).find(".dhsjThresholdt_input").val()!="" && !numPoint2.test($(element).find(".dhsjThresholdt_input").val())){
				// 	alert("分钟格式不正确。");
				// 	$(element).find(".time_button_edit").click();
				// 	$(element).find(".dhsjThresholdt_input").focus();
				// 	formable=false;
				// 	return false;
			}else if($(element).find(".dhsjCost_input").val()!="" && !numPoint.test($(element).find(".dhsjCost_input").val())){
				alert("金额格式不正确。");
				$(element).find(".time_button_edit").click();
				$(element).find(".dhsjCost_input").focus();
				formable=false;
				return false;
			}else  if($(element).find(".cgzl_input").val()!="" && !numPointweight.test($(element).find(".cgzl_input").val())){
				alert("重量格式不正确。");
				$(element).find(".time_button_edit").click();
				$(element).find(".cgzl_input").focus();
				formable = false;
				return false;
			} else if ($(element).find(".zlUnit_input").val() != "" && !numPointweight.test($(element).find(".zlUnit_input").val())) {
				alert("重量格式不正确。");
				$(element).find(".time_button_edit").click();
				$(element).find(".zlUnit_input").focus();
				formable = false;
				return false;
				// }else  if($(element).find(".zlThresholdt_input").val()!="" && !numPointweight.test($(element).find(".zlThresholdt_input").val())){
				//     alert("重量格式不正确。");
				//     $(element).find(".time_button_edit").click();
				//     $(element).find(".zlThresholdt_input").focus();
				//     formable=false;
				//     return false;
			}else if($(element).find(".zlCost_input").val()!="" && !numPoint.test($(element).find(".zlCost_input").val())){
				alert("金额格式不正确。");
				$(element).find(".time_button_edit").click();
				$(element).find(".zlCost_input").focus();
				formable = false;
				return false;
			}

			// var last_end_distance=0;
			$(element).find(".distance_tr").each(function(i,e){
				var start_distance=$(e).find(".distance_td_distance_start").val();
				var end_distance=$(e).find(".distance_td_distance").val();
				var distance_money=$(e).find(".distance_td_money").val();
				if(!start_distance){
					// console.log($(this).parent().parent().parent().next().children().eq(0).children().eq(0));
					// debugger
					start_distance=$(this).parent().parent().parent().next().find(".this_qblc").html();
				}
				if(!end_distance){
					end_distance=9999999999;
					$(e).find(".distance_td_distance").val(9999999999);
				}
				if(start_distance!="" && !numPoint.test(start_distance)){
					alert("开始里程格式不正确。");
					$(e).find(".distance_td_edit").click();
					$(e).find(".distance_td_distance_start").focus();
					formable=false;
					return false;
				}
				else if(end_distance!="" && !numPoint.test(end_distance)){
					alert("结束里程格式不正确。");
					$(e).find(".distance_td_edit").click();
					$(e).find(".distance_td_distance").focus();
					formable=false;
					return false;
				}
				else if(distance_money=="" || !numPoint.test(distance_money)){
					alert("增长价格式不正确。");
					$(e).find(".distance_td_edit").click();
					$(e).find(".distance_td_money").focus();
					formable=false;
					return false;
				}

				if(parseFloat(start_distance)>parseFloat(end_distance)){
					alert("结束里程必须大于开始里程");
					$(element).find(".time_button_edit").click();
					$(e).find(".distance_td_distance").focus();
					formable=false;
					return false;
				}

				// if(parseFloat(end_distance)>parseFloat(last_end_distance)){
				// 	last_end_distance=end_distance;
				// }
			});

			var last_end_weight = 0;
			$(element).find(".weight_tr").each(function (i, e) {
				var start_weight = $(e).find(".weight_td_weight_start").val();
				var end_weight = $(e).find(".weight_td_weight").val();
				var weight_money = $(e).find(".weight_td_money").val();

				if (!start_weight) {
					start_weight = 0;
				}

				if (start_weight != "" && !numPoint.test(start_weight)) {
					alert("开始重量格式不正确。");
					$(e).find(".weight_td_edit").click();
					$(e).find(".weight_td_weight_start").focus();
					formable = false;
					return false;
				} else if (end_weight != "" && !numPoint.test(end_weight)) {
					alert("结束重量格式不正确。");
					$(e).find(".weight_td_edit").click();
					$(e).find(".weight_td_weight").focus();
					formable = false;
					return false;
				} else if (weight_money != "" && !numPoint.test(weight_money)) {
					alert("增长价格式不正确。");
					$(e).find(".weight_td_edit").click();
					$(e).find(".weight_td_money").focus();
					formable = false;
					return false;
				}

				if (parseFloat(start_weight) > parseFloat(end_weight)) {
					alert("结束重量必须大于开始重量");
					$(element).find(".time_button_edit").click();
					$(e).find(".weight_td_weight").focus();
					formable = false;
					return false;
				}

				if (parseFloat(end_weight) > parseFloat(last_end_weight)) {
					last_end_weight = end_weight;
				}
			});


			if(!formable){
				return false;
			}

			// if($(element).find(".distance_tr").length>0 && last_end_distance!=$(element).find(".qblc_input").val()){
			// 	alert("超出里程必须等于最大结束里程");
			// 	$(element).find(".time_button_edit").click();
			// 	$(element).find(".qblc_input").focus();
			// 	formable=false;
			// 	return false;
			// }

			if ($(element).find(".weight_tr").length > 0 && last_end_weight != $(element).find(".cgzl_input").val()) {
				alert("超出重量必须等于最大重量");
				$(element).find(".time_button_edit").click();
				$(element).find(".cgzl_input").focus();
				formable = false;
				return false;
			}

		});

		if (!formable) {
			return false;
		}

		thisform.find(".item-length").each(function (index, element) {
			$(element).find(".distance_tr").each(function (i, e) {
				$(e).find(".distance_td_distance_start").attr("name", $(element).find(".cost_input").attr("data-name") + ".chargeStartDistances[" + i + "].startdistance");
				$(e).find(".distance_td_distance").attr("name", $(element).find(".cost_input").attr("data-name") + ".chargeStartDistances[" + i + "].distance");
				$(e).find(".distance_td_money").attr("name", $(element).find(".cost_input").attr("data-name") + ".chargeStartDistances[" + i + "].money");
			});
			$(element).find(".weight_tr").each(function (i, e) {
				$(e).find(".weight_td_weight_start").attr("name", $(element).find(".cost_input").attr("data-name") + ".chargeStartNewWeights[" + i + "].startweight");
				$(e).find(".weight_td_weight").attr("name", $(element).find(".cost_input").attr("data-name") + ".chargeStartNewWeights[" + i + "].weight");
				$(e).find(".weight_td_money").attr("name", $(element).find(".cost_input").attr("data-name") + ".chargeStartNewWeights[" + i + "].money");
			});

			var djglUnit_input = $(element).find(".djglUnit_input").val();
			var djsjUnit_input = $(element).find(".djsjUnit_input").val();
			var dhsjUnit_input = $(element).find(".dhsjUnit_input").val();
			var zlUnit_input = $(element).find(".zlUnit_input").val();
			if (djglUnit_input == 0) {
				$(element).find(".djglThresholdt_input").val(0);
				$(element).find(".djglCost_input").val(0);
			}
			if (djsjUnit_input == 0) {
				$(element).find(".djsjThresholdt_input").val(0);
				$(element).find(".djsjCost_input").val(0);
			}
			if (dhsjUnit_input == 0) {
				$(element).find(".dhsjThresholdt_input").val(0);
				$(element).find(".dhsjCost_input").val(0);
			}
			if (zlUnit_input == 0) {
				$(element).find(".zlThresholdt_input").val(0);
				$(element).find(".zlCost_input").val(0);
			}
		});

		$(thisform).find(".area-save").attr("disabled", true);

		$.post(thisform.attr("action"), thisform.serialize(), function (result) {
			if (result.success) {
				$.scojs_message(result.message, $.scojs_message.TYPE_OK);
				window.location.reload(true);
			} else {
				$.scojs_message(result.message, $.scojs_message.TYPE_ERROR);
				$(thisform).find(".area-save").attr("disabled", false);
			}
		});

		return false;
	});


	$(document).on('click', '.area-edit', function () {
		$(this).parent().parent().find(".name_span").hide();
		$(this).parent().parent().find(".name_input").show();
		$(this).parent().parent().find(".memo_span").hide();
		$(this).parent().parent().find(".memo_textarea").show();
	});

	//时间段删除
	$(document).on('click', '.time_button_delete', function () {
		$(this).parent().parent().parent().parent().parent().parent().remove();
	});

	//时间段修改
	$(document).on('click','.time_button_edit',function(){
		var table=$(this).parent().parent().parent().parent().find("table");
		$(this).parent().parent().find(".time_content span").hide();
		$(this).parent().parent().find(".time_content select").show();
		$(this).parent().parent().find(".time_content input").show();
		// console.log($(this).parent().parent().parent().parent().find(".time_content2 input"));
		$(this).parent().parent().parent().parent().find(".time_content2 span").hide();
		$(this).parent().parent().parent().parent().find(".time_content2 input").show();

		if(table.parent().parent().css("display")=="none"){
			$(this).parent().parent().find("a").click();
		}
	});

	//里程价格添加
	$(document).on('click','.time_button_add',function(){
		var table=$(this).parent().parent().parent().parent().find(".distance-table");
		var length=table.find(".distance_tr").length;
		var content="";
		content+="<tr class='distance_tr'>";
		if(length==0){
			content+="<td><input class='distance_td_distance_start' type='number' min='0' required value='"+$(this).parent().parent().parent().next().find(".this_qblc").html()+"' /></td>";
		}
		else{
			var value=table.find(".distance_tr:last").find(".distance_td_distance").val();
			content+="<td><input class='distance_td_distance_start' type='number' min='0' required value='"+value+"' /></td>";
		}
		content+="<td><input class='distance_td_distance' type='number' min='0' required /></td>"+
			"<td><input class='distance_td_money' type='number' min='0' required /></td>"+
			"<td><a href='javascript:;' class='distance_td_delete'>删除</a></td>"+
			"</tr>";
		table.find("tbody").append(content);
		if(table.parent().parent().css("display")=="none"){
			$(this).parent().parent().find("a").click();
		}
	});

	//里程价格删除
	$(document).on('click', '.distance_td_delete', function () {
		$(this).parent().parent().remove();
	});

	//里程价格编辑
	$(document).on('click', '.distance_td_edit', function () {
		$(this).parent().parent().find("span").hide();
		$(this).parent().parent().find("input").show();
	});

	//里程距离改变
	$(document).on('change', '.distance_td_distance', function () {
		$($(this).parent().parent().next().find("span")[0]).html($(this).val());
		$(this).parent().parent().next().find(".distance_td_distance_start").val($(this).val());
	});


	//重量价格添加
	$(document).on('click', '.weight_button_add', function () {
		var table = $(this).parent().parent().parent().parent().find(".weight-table");
		var length = table.find(".weight_tr").length;
		var content = "";
		content += "<tr class='weight_tr'>";
		if (length == 0) {
			content += "<td>0</td>";
		} else {
			var value = table.find(".weight_tr:last").find(".weight_td_weight").val();
			content += "<td><input class='weight_td_weight_start' type='number' min='0' required value='" + value + "' /></td>";
		}
		content += "<td><input class='weight_td_weight' type='number' min='0' required /></td>" +
			"<td><input class='weight_td_money' type='number' min='0' required /></td>" +
			"<td><a href='javascript:;' class='weight_td_delete'>删除</a></td>" +
			"</tr>";
		table.find("tbody").append(content);
		if (table.parent().parent().css("display") == "none") {
			$(this).parent().parent().find("a").click();
		}
	});

	//重量价格删除
	$(document).on('click', '.weight_td_delete', function () {
		$(this).parent().parent().remove();
	});

	//重量价格编辑
	$(document).on('click', '.weight_td_edit', function () {
		$(this).parent().parent().find("span").hide();
		$(this).parent().parent().find("input").show();
	});

	//重量距离改变
	$(document).on('change', '.weight_td_weight', function () {
		$($(this).parent().parent().next().find("span")[0]).html($(this).val());
		$(this).parent().parent().next().find(".weight_td_weight_start").val($(this).val());
	});



	$(document).on('click','.area-add',function(){
		var currItemLength=$(this).parent().parent().find(".item-length").length;
		var randomid=randomString(5);
		var newitem = '<div class="item-length">'+
			'<div class="panel-group">'+
			'<div class="panel panel-default">'+
			'<div class="panel-heading">'+
			'<h4 class="panel-title">'+
			'<a data-toggle="collapse" href="#collapseOne_'+randomid+'">'+
			'展开'+
			'</a>'+
			'<span class="time_content">'+
			'开始服务时间（'+
			'<select name="chargeStartTimes['+currItemLength+'].startHour" class="startHour_select bottom_border">'+$("#item-hour-div-start").html()+'</select>'+
			'：'+
			'<select name="chargeStartTimes['+currItemLength+'].startMinute" class="startMinute_select bottom_border">'+$("#item-minute-div-start").html()+'</select>'+
			'-'+
			'<select name="chargeStartTimes['+currItemLength+'].endHour" class="endHour_select bottom_border">'+$("#item-hour-div-end").html()+'</select>'+
			'：'+
			'<select name="chargeStartTimes['+currItemLength+'].endMinute" class="endMinute_select bottom_border">'+$("#item-minute-div-end").html()+'</select>'+
			'）'+
			'起步价<input type="number" value="0" name="chargeStartTimes['+currItemLength+'].cost" data-name="chargeStartTimes['+currItemLength+']" class="cost_input bottom_border" style="width:60px;" required min="0"/>元'+
			'</span>'+
			'<span class="time_button pull-right">'+
			'<button type="button" class="pull-right btn btn-default btn-xs time_button_delete">删除</button>'+
			'<button type="button" class="pull-right btn btn-default btn-xs time_button_edit">修改</button>'+
			'<button type="button" class="pull-right btn btn-default btn-xs time_button_add">添加里程价格</button>'+
			'<button type="button" class="pull-right btn btn-default btn-xs weight_button_add">添加重量价格</button>'+
			'</span>'+
			'</h4>'+
			'</div>'+

			'<div id="collapseOne_'+randomid+'" class="panel-collapse collapse">'+
			'<div class="panel-body">'+
			'<table class="table table-condensed table-bordered distance-table">'+
			'<tr style="font-size:14px;">'+
			'<th>开始里程(公里)</th>'+
			'<th>结束里程(公里)</th>'+
			'<th>增长价(元)</th>'+
			'<th>操作</th>'+
			'</tr>'+
			'</table>'+
			'<hr/>'+
			'<table class="table table-condensed table-bordered weight-table">'+
			'<tr style="font-size:14px;">'+
			'<th>开始重量(公斤)</th>'+
			'<th>结束重量(公斤)</th>'+
			'<th>增长价(元)</th>'+
			'<th>操作</th>'+
			'</tr>'+
			'</table>'+
			'<hr/>'+
			'<span class="time_content2">'+
			'超过（<input type="number" value="0" name="chargeStartTimes['+currItemLength+'].qblc" class="qblc_input bottom_border" style="width:60px;" required min="0"/>公里），'+
			'以后每<input type="number" value="0" name="chargeStartTimes['+currItemLength+'].djglUnit" class="djglUnit_input bottom_border" style="width:60px;" required min="0"/>公里'+
			// '（不足<input type="number" value="0" name="chargeStartTimes['+currItemLength+'].djglThresholdt" class="djglThresholdt_input bottom_border" style="width:60px;" required min="0"/>公里不计费）'+
			'加收<input type="number" value="0" name="chargeStartTimes['+currItemLength+'].djglCost" class="djglCost_input bottom_border" style="width:60px;" required min="0"/>元；'+
			'<p></p>'+
			'起步后<input type="number" value="0" name="chargeStartTimes['+currItemLength+'].qbsj" class="qbsj_input bottom_border" style="width:60px;" required min="0"/>分钟内不收费，'+
			'以后每<input type="number" value="0" name="chargeStartTimes['+currItemLength+'].djsjUnit" class="djsjUnit_input bottom_border" style="width:60px;" required min="0"/>分钟'+
			// '（ 不足<input type="number" value="0" name="chargeStartTimes['+currItemLength+'].djsjThresholdt" class="djsjThresholdt_input bottom_border" style="width:60px;" required min="0"/>分钟不收费）'+
			'加收<input type="number" value="0" name="chargeStartTimes['+currItemLength+'].djsjCost" class="djsjCost_input bottom_border" style="width:60px;" required min="0"/>元；'+
			'<p></p>'+
			'免费等候<input type="number" value="0" name="chargeStartTimes['+currItemLength+'].mfdhsj" class="mfdhsj_input bottom_border" style="width:60px;" required min="1"/>分钟，'+
			'到达则立即加收<input type="number" value="0" name="chargeStartTimes['+currItemLength+'].dhsjAtonceCost" class="dhsjAtonceCost_input bottom_border" style="width:60px;" required min="0"/>元，'+
			'后每<input type="number" value="0" name="chargeStartTimes['+currItemLength+'].dhsjUnit" class="dhsjUnit_input bottom_border" style="width:60px;" required min="0"/>分钟'+
			// '（ 低于<input type="number" value="0" name="chargeStartTimes['+currItemLength+'].dhsjThresholdt" class="dhsjThresholdt_input bottom_border" style="width:60px;" required min="0"/>分钟不计费）'+
			'加收<input type="number" value="0" name="chargeStartTimes['+currItemLength+'].dhsjCost" class="dhsjCost_input bottom_border" style="width:60px;" required min="0"/>元；'+
			'<p></p>'+
			'超过（<input type="number" value="0" name="chargeStartTimes['+currItemLength+'].cgzl" class="cgzl_input bottom_border" style="width:60px;" required min="0"/>公斤），'+
			'以后每<input type="number" value="0" name="chargeStartTimes['+currItemLength+'].zlUnit" class="zlUnit_input bottom_border" style="width:60px;" required min="0"/>公斤'+
			// '（不足<input type="number" value="0" name="chargeStartTimes['+currItemLength+'].zlThresholdt" class="zlThresholdt_input bottom_border" style="width:60px;" required min="0"/>公斤不计费）'+
			'加收<input type="number" value="0" name="chargeStartTimes['+currItemLength+'].zlCost" class="zlCost_input bottom_border" style="width:60px;" required min="0"/>元。'+
			'</span>'+
			'</div>'+
			'</div>'+

			'</div>'+
			'</div>'+

			'</div>';

		$(this).parent().parent().find(".time_panel_body").prepend(newitem);
		$(this).parent().parent().find(".time_panel_body:first").find(".time_button_edit").click();

		currItemLength++;
	});

	$("#add-new-area").click(function () {
//    	$(this).attr("disabled",true);
		var companySelect = '<select style="height:24px;" name="companyId">';
		$.ajax({
			url: ctx + '/area/queryCompanys',
			type: 'get',
			dataType: 'json',
			async: false,
			success: function(result){
				var data = result.data;
				$.each(data,function(i,company){
					companySelect += '<option value="'+company.id+'">'+company.companyName+'</option>';
				})
			}
		})
		companySelect += '</select>'
		var randomid=randomString(5);
		var newitem = '<form action="'+ctx+'/area/create" class="form-horizontal" method="post">'+
			'<div class="col-md-12">'+
			'<div class="panel panel-default">'+
			'<div class="panel-heading">'+
			'收费名称：<input type="text" name="name" class="name_input" style="width:150px;" required/>' +
			'所属公司：' + companySelect +
			'<button type="button" class="deleteArea-new pull-right button button-pill button-flat-caution button-tiny"><span class="glyphicon glyphicon-remove"></span>&nbsp;删除</button>'+
			'<button type="button" class="area-add pull-right button button-pill button-flat-action button-tiny"><span class="glyphicon glyphicon-plus"></span>&nbsp;新增时间段</button>'+
			'<button type="submit" class="area-save pull-right button button-pill button-flat button-tiny"><span class="glyphicon glyphicon-floppy-disk"></span>&nbsp;保存</button>'+
			'</div>'+
			'<div class="panel-body time_panel_body">'+

			'<div class="item-length">'+
			'<div class="panel-group">'+
			'<div class="panel panel-default">'+
			'<div class="panel-heading">'+
			'<h4 class="panel-title">'+
			'<a data-toggle="collapse" href="#collapseOne_'+randomid+'">'+
			'展开'+
			'</a>'+
			'<span class="time_content">'+
			'开始服务时间（'+
			'<select name="chargeStartTimes[0].startHour" class="startHour_select bottom_border">'+$("#item-hour-div-start").html()+'</select>'+
			'：'+
			'<select name="chargeStartTimes[0].startMinute" class="startMinute_select bottom_border">'+$("#item-minute-div-start").html()+'</select>'+
			'-'+
			'<select name="chargeStartTimes[0].endHour" class="endHour_select bottom_border">'+$("#item-hour-div-end").html()+'</select>'+
			'：'+
			'<select name="chargeStartTimes[0].endMinute" class="endMinute_select bottom_border">'+$("#item-minute-div-end").html()+'</select>'+
			'）'+
			'起步价<input type="number" value="0" name="chargeStartTimes[0].cost" data-name="chargeStartTimes[0]" class="cost_input bottom_border" style="width:60px;" required min="0"/>元'+
			'</span>'+
			'<span class="time_button pull-right">'+
			'<button type="button" class="pull-right btn btn-default btn-xs time_button_delete">删除</button>'+
			'<button type="button" class="pull-right btn btn-default btn-xs time_button_edit">修改</button>'+
			'<button type="button" class="pull-right btn btn-default btn-xs time_button_add">添加里程价格</button>'+
			'<button type="button" class="pull-right btn btn-default btn-xs weight_button_add">添加重量价格</button>'+
			'</span>'+
			'</h4>'+
			'</div>'+

			'<div id="collapseOne_'+randomid+'" class="panel-collapse collapse">'+
			'<div class="panel-body">'+
			'<table class="table table-condensed table-bordered distance-table">'+
			'<tr style="font-size:14px;">'+
			'<th>开始里程(公里)</th>'+
			'<th>结束里程(公里)</th>'+
			'<th>增长价(元)</th>'+
			'<th>操作</th>'+
			'</tr>'+
			'</table>'+
			'<hr/>'+
			'<table class="table table-condensed table-bordered weight-table">'+
			'<tr style="font-size:14px;">'+
			'<th>开始重量(公斤)</th>'+
			'<th>结束重量(公斤)</th>'+
			'<th>增长价(元)</th>'+
			'<th>操作</th>'+
			'</tr>'+
			'</table>'+
			'<hr/>'+
			'<span class="time_content2">'+
			'超过（<input type="number" value="0" name="chargeStartTimes[0].qblc" class="qblc_input bottom_border" style="width:60px;" required min="0"/>公里），'+
			'以后每<input type="number" value="0" name="chargeStartTimes[0].djglUnit" class="djglUnit_input bottom_border" style="width:60px;" required min="0"/>公里'+
			// '（不足<input type="number" value="0" name="chargeStartTimes[0].djglThresholdt" class="djglThresholdt_input bottom_border" style="width:60px;" required min="0"/>公里不计费）'+
			'加收<input type="number" value="0" name="chargeStartTimes[0].djglCost" class="djglCost_input bottom_border" style="width:60px;" required min="0"/>元；'+
			'<p></p>'+
			'起步后<input type="number" value="0" name="chargeStartTimes[0].qbsj" class="qbsj_input bottom_border" style="width:60px;" required min="0"/>分钟内不收费，'+
			'以后每<input type="number" value="0" name="chargeStartTimes[0].djsjUnit" class="djsjUnit_input bottom_border" style="width:60px;" required min="0"/>分钟'+
			// '（ 不足<input type="number" value="0" name="chargeStartTimes[0].djsjThresholdt" class="djsjThresholdt_input bottom_border" style="width:60px;" required min="0"/>分钟不收费）'+
			'加收<input type="number" value="0" name="chargeStartTimes[0].djsjCost" class="djsjCost_input bottom_border" style="width:60px;" required min="0"/>元；'+
			'<p></p>'+
			'免费等候<input type="number" value="0" name="chargeStartTimes[0].mfdhsj" class="mfdhsj_input bottom_border" style="width:60px;" required min="1"/>分钟，'+
			'到达则立即加收<input type="number" value="0" name="chargeStartTimes[0].dhsjAtonceCost" class="dhsjAtonceCost_input bottom_border" style="width:60px;" required min="0"/>元，'+
			'后每<input type="number" value="0" name="chargeStartTimes[0].dhsjUnit" class="dhsjUnit_input bottom_border" style="width:60px;" required min="0"/>分钟'+
			// '（ 低于<input type="number" value="0" name="chargeStartTimes[0].dhsjThresholdt" class="dhsjThresholdt_input bottom_border" style="width:60px;" required min="0"/>分钟不计费）'+
			'加收<input type="number" value="0" name="chargeStartTimes[0].dhsjCost" class="dhsjCost_input bottom_border" style="width:60px;" required min="0"/>元；'+
			'<p></p>'+
			'超过（<input type="number" value="0" name="chargeStartTimes[0].cgzl" class="cgzl_input bottom_border" style="width:60px;" required min="0"/>公斤），'+
			'以后每<input type="number" value="0" name="chargeStartTimes[0].zlUnit" class="zlUnit_input bottom_border" style="width:60px;" required min="0"/>公斤'+
			// '（不足<input type="number" value="0" name="chargeStartTimes[0].zlThresholdt" class="zlThresholdt_input bottom_border" style="width:60px;" required min="0"/>公斤不计费）'+
			'加收<input type="number" value="0" name="chargeStartTimes[0].zlCost" class="zlCost_input bottom_border" style="width:60px;" required min="0"/>元。'+
			'</span>'+
			'</div>'+
			'</div>'+

			'</div>'+
			'</div>'+

			'</div>'+

			'<h4 class="text-primary">收费说明：</h4>'+
			'<p class="text-muted">'+
			'<textarea cols="100" rows="5" name="memo"></textarea>'+
			'</p>'+
			'</div>'+
			'</div>'+
			'</div>'+
			'</form>';

		$(".area_container").prepend(newitem);

		$(".area_container").find(".time_panel_body:first").find(".time_button_edit").click();

		// var companySelect = '<select style="height:24px;" name="companyId">';
		// $.ajax({
		// 	url: ctx + '/area/queryCompanys',
		// 	type: 'get',
		// 	dataType: 'json',
		// 	async: false,
		// 	success: function(result){
		// 		var data = result.data;
		// 		$.each(data,function(i,company){
		// 			companySelect += '<option value="'+company.id+'">'+company.companyName+'</option>';
		// 		})
		// 	}
		// })
		// companySelect += '</select>'
		// console.log(companySelect);
		// var randomid = randomString(5);
		// var newitem = '<form action="' + ctx + '/area/create" class="form-horizontal" method="post">' +
		// 	'<div class="col-md-12">' +
		// 	'<div class="panel panel-default">' +
		// 	'<div class="panel-heading">' +
		// 	'<div>' +
		// 	'   <span>收费标准名称：</span>' +
		// 	'   <input type="text" name="name" class="name_input" style="width:150px;" required/>' +
		// 	'   <span style="padding-left: 10px;">请选择所属公司：</span>' +
		// 	companySelect +
		//
		// 	'<button type="button" class="deleteArea-new pull-right button button-pill button-flat-caution button-tiny"><span class="glyphicon glyphicon-remove"></span>&nbsp;删除</button>' +
		// 	'<button type="button" class="area-add pull-right button button-pill button-flat-action button-tiny"><span class="glyphicon glyphicon-plus"></span>&nbsp;新增时间段</button>' +
		// 	'<button type="submit" class="area-save pull-right button button-pill button-flat button-tiny"><span class="glyphicon glyphicon-floppy-disk"></span>&nbsp;保存</button>' +
		// 	'</div>' +
		// 	'</div>' +
		// 	'<div class="panel-body time_panel_body">' +
		//
		// 	'<div class="item-length">' +
		// 	'<div class="panel-group">' +
		// 	'<div class="panel panel-default">' +
		// 	'<div class="panel-heading">' +
		// 	'<h4 class="panel-title">' +
		// 	'<a data-toggle="collapse" href="#collapseOne_' + randomid + '">' +
		// 	'展开' +
		// 	'</a>' +
		// 	'<span class="time_content">' +
		// 	'开始服务时间（' +
		// 	'<select name="chargeStartTimes[0].startHour" class="startHour_select bottom_border">' + $("#item-hour-div-start").html() + '</select>' +
		// 	'：' +
		// 	'<select name="chargeStartTimes[0].startMinute" class="startMinute_select bottom_border">' + $("#item-minute-div-start").html() + '</select>' +
		// 	'-' +
		// 	'<select name="chargeStartTimes[0].endHour" class="endHour_select bottom_border">' + $("#item-hour-div-end").html() + '</select>' +
		// 	'：' +
		// 	'<select name="chargeStartTimes[0].endMinute" class="endMinute_select bottom_border">' + $("#item-minute-div-end").html() + '</select>' +
		// 	'）' +
		// 	'起步价<input type="number" value="0" name="chargeStartTimes[0].cost" data-name="chargeStartTimes[0]" class="cost_input bottom_border" style="width:60px;" required min="0"/>元' +
		// 	'</span>' +
		// 	'<span class="time_button pull-right">' +
		// 	'<button type="button" class="pull-right btn btn-default btn-xs time_button_delete">删除</button>' +
		// 	'<button type="button" class="pull-right btn btn-default btn-xs time_button_edit">修改</button>' +
		// 	'<button type="button" class="pull-right btn btn-default btn-xs time_button_add">添加里程价格</button>' +
		// 	'<button type="button" class="pull-right btn btn-default btn-xs weight_button_add">添加重量价格</button>' +
		// 	'</span>' +
		// 	'</h4>' +
		// 	'</div>' +
		//
		// 	'<div id="collapseOne_' + randomid + '" class="panel-collapse collapse">' +
		// 	'<div class="panel-body">' +
		// 	'<table class="table table-condensed table-bordered distance-table">' +
		// 	'<tr style="font-size:14px;">' +
		// 	'<th>开始里程(公里)</th>' +
		// 	'<th>结束里程(公里)</th>' +
		// 	'<th>增长价(元)</th>' +
		// 	'<th>操作</th>' +
		// 	'</tr>' +
		// 	'</table>' +
		// 	'<hr/>' +
		// 	'<table class="table table-condensed table-bordered weight-table">' +
		// 	'<tr style="font-size:14px;">' +
		// 	'<th>开始重量(公斤)</th>' +
		// 	'<th>结束重量(公斤)</th>' +
		// 	'<th>增长价(元)</th>' +
		// 	'<th>操作</th>' +
		// 	'</tr>' +
		// 	'</table>' +
		// 	'<hr/>' +
		// 	'<span class="time_content2">' +
		// 	'超过（<input type="number" value="0" name="chargeStartTimes[0].qblc" class="qblc_input bottom_border" style="width:60px;" required min="0"/>公里），' +
		// 	'以后每<input type="number" value="0" name="chargeStartTimes[0].djglUnit" class="djglUnit_input bottom_border" style="width:60px;" required min="0"/>公里' +
		// 	'（不足<input type="number" value="0" name="chargeStartTimes[0].djglThresholdt" class="djglThresholdt_input bottom_border" style="width:60px;" required min="0"/>公里不计费）' +
		// 	'加收<input type="number" value="0" name="chargeStartTimes[0].djglCost" class="djglCost_input bottom_border" style="width:60px;" required min="0"/>元；' +
		// 	'<p></p>' +
		// 	'起步后<input type="number" value="0" name="chargeStartTimes[0].qbsj" class="qbsj_input bottom_border" style="width:60px;" required min="0"/>分钟内不收费，' +
		// 	'以后每<input type="number" value="0" name="chargeStartTimes[0].djsjUnit" class="djsjUnit_input bottom_border" style="width:60px;" required min="0"/>分钟' +
		// 	'（ 不足<input type="number" value="0" name="chargeStartTimes[0].djsjThresholdt" class="djsjThresholdt_input bottom_border" style="width:60px;" required min="0"/>分钟不收费）' +
		// 	'加收<input type="number" value="0" name="chargeStartTimes[0].djsjCost" class="djsjCost_input bottom_border" style="width:60px;" required min="0"/>元；' +
		// 	'<p></p>' +
		// 	'免费等候<input type="number" value="0" name="chargeStartTimes[0].mfdhsj" class="mfdhsj_input bottom_border" style="width:60px;" required min="1"/>分钟，' +
		// 	'到达则立即加收<input type="number" value="0" name="chargeStartTimes[0].dhsjAtonceCost" class="dhsjAtonceCost_input bottom_border" style="width:60px;" required min="0"/>元，' +
		// 	'后每<input type="number" value="0" name="chargeStartTimes[0].dhsjUnit" class="dhsjUnit_input bottom_border" style="width:60px;" required min="0"/>分钟' +
		// 	'（ 低于<input type="number" value="0" name="chargeStartTimes[0].dhsjThresholdt" class="dhsjThresholdt_input bottom_border" style="width:60px;" required min="0"/>分钟不计费）' +
		// 	'加收<input type="number" value="0" name="chargeStartTimes[0].dhsjCost" class="dhsjCost_input bottom_border" style="width:60px;" required min="0"/>元；' +
		// 	'<p></p>' +
		// 	'超过（<input type="number" value="0" name="chargeStartTimes[0].cgzl" class="cgzl_input bottom_border" style="width:60px;" required min="0"/>公斤），' +
		// 	'以后每<input type="number" value="0" name="chargeStartTimes[0].zlUnit" class="zlUnit_input bottom_border" style="width:60px;" required min="0"/>公斤' +
		// 	'（不足<input type="number" value="0" name="chargeStartTimes[0].zlThresholdt" class="zlThresholdt_input bottom_border" style="width:60px;" required min="0"/>公斤不计费）' +
		// 	'加收<input type="number" value="0" name="chargeStartTimes[0].zlCost" class="zlCost_input bottom_border" style="width:60px;" required min="0"/>元。' +
		// 	'</span>' +
		// 	'</div>' +
		// 	'</div>' +
		//
		// 	'</div>' +
		// 	'</div>' +
		//
		// 	'</div>' +
		//
		// 	'<h4 class="text-primary">收费说明：</h4>' +
		// 	'<p class="text-muted">' +
		// 	'<textarea cols="100" rows="5" name="memo"></textarea>' +
		// 	'</p>' +
		// 	'</div>' +
		// 	'</div>' +
		// 	'</div>' +
		// 	'</form>';
		//
		// $(".area_container").prepend(newitem);
		//
		// $(".area_container").find(".time_panel_body:first").find(".time_button_edit").click();

	});

	$(document).on("keydown","body",function(){
		if(window.event.keyCode == 13){
			$("#searchButton").click();
		}
	});

});

function addZero(obj) {
	if (obj != null) {
		obj=parseInt(obj);
	}
	if (obj<=10) {
		obj="0"+obj;
	}
	return obj;
}

function deleteItem(btn){
	$(btn).parent().parent().remove();
}
function padZero(hourormin){
	if(hourormin.length==1){
		return "0"+hourormin;
	}
	else{
		return hourormin;
	}
}
function randomString(len){
	len = len || 32;
	var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
	var maxPos = $chars.length;
	var pwd = '';
	for (var i = 0; i < len; i++) {
		pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
	}
	return pwd;
}


